package com.supersonic.backend.DAOImpl;

import java.util.List;





import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.supersonic.backend.DAO.IUserDAO;
import com.supersonic.backend.model.User;

@Repository(value="userDao")
public class UserDAOImpl extends BaseDAOImpl<User, String> implements IUserDAO {
	
	@Autowired
	protected SessionFactory sessionFactory;

	public List<User> list() {
		@SuppressWarnings("unchecked")
		List<User> listUser = (List<User>) sessionFactory.getCurrentSession()
				.createCriteria(User.class)
				.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();

		return listUser;
	}
	
	public void addUser(User user) {
		sessionFactory.getCurrentSession().save(user);
		
	}
	
	public User findById(String id) {
		return (User)sessionFactory.getCurrentSession().get(User.class, id);
	}

}
